<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="./vue.js"></script>
</head>
<body>

	<div id="app">
		<input type="text" v-model="inputValue">
		<button v-on:click="handleBtnClick">提交</button>
		<ul>
			<!-- v-bind和: 等价 -->
			<!-- v-on:click="xxx"和@click="xxx"等价 -->
			<todo-list v-bind:content="item"
					   :index="index" 
					   v-for="(item, index) in list"
					   @delete="handleItemDelete">{{item}}
			</todo-list>
		</ul>
	</div>

	<script>

		var TodoList = {
			props: ['content', 'index'],
			template: "<li @click='handleItemClick'>{{content}}</li>",
			methods: {
				handleItemClick: function () {
					this.$emit('delete', this.index);
				}
			}
		};

		var app = new Vue({
			el: '#app',
			components: {
				TodoList: TodoList
			},
			data: {
				list: [],
				inputValue: ''
			},
			methods: {
				handleBtnClick: function () {
					this.list.push(this.inputValue);
				},
				handleItemDelete: function (index) {
					this.list.splice(index, 1);
				}
			}
		});
	</script>
</body>
</html>